# = test.settings.1.rb - Contact Settings Test
# See LICENSE.txt for licensing details.
#
# == Description
#To test the functionality for Contact Settings
require 'watir'
require 'watir/WindowHelper'
include Watir
require 'test/unit'
require '../watir.config.rb'
require '../resources/functions.rb'

class TC_ChangeContactSettings_test < Test::Unit::TestCase
    
    def startup
      $AdminEmail = randomChar(6) + '@' + randomChar(8) + '.com'
      $OrgEmail = randomChar(5) + '@' + randomChar(3) + '.com'
      $OrgName = randomChar(20)
      $OrgPhone = '777-777-7777'
      $OrgFax = '555-555-5555'
      $OrgAddress = randomChar(100)
      @@ie = Watir::IE.start($SITE_URL)
    end
  
    def ie
      if defined? @@ie
        @@ie
      else
        startup
      end
    end

    def test_01_verifyHomeText
      assert(ie.contains_text(/Community Server/))		
    end
      
    def test_02_verifyLoginLinksExist
      if !(ie.link(:text, 'Sign in').exists?)
        ie.goto($SITE_URL + 'logout.aspx')
        ie.refresh
        ie.goto($SITE_URL)
        ie.refresh
      end
	  end
    
    def test_03_navigateToLogin
      ie.link(:text, 'Sign in').click
      assert(ie.contains_text("Sign in name"))
    end
	  
	  def test_04_populateLoginForm
      ie.text_field(:id, /username$/).value = $ADMIN_USER
      assert(ie.text_field(:id, /username$/).verify_contains($ADMIN_USER))
      
      ie.text_field(:id, /password$/).value = $ADMIN_PASSWORD
      assert(ie.text_field(:id, /password$/).verify_contains($ADMIN_PASSWORD))
	  end
	  
    def test_05_submitLoginForm
      ie.link(:id, /loginButton$/).click
      test_01_verifyHomeText
    end
    
    def test_06_verifyControlPanel
      assert(ie.link(:text, /Control Panel/).exists?)
      ie.link(:text, /Control Panel/).click
      assert(ie.contains_text(/Community Server Announcements/))      
    end
    
    def test_07_verifyControlPanelTabBarLinks
      assert_equal $SITE_URL + 'controlpanel/default.aspx', ie.link(:text, 'Dashboard').href
      assert_equal $SITE_URL + 'controlpanel/blogs', ie.link(:text, 'My Blogs').href
      assert_equal $SITE_URL + 'controlpanel/photos/', ie.link(:text, 'My Photos').href
      assert_equal $SITE_URL + 'controlpanel/files', ie.link(:text, 'My Files').href
      assert_equal $SITE_URL + 'controlpanel/moderation', ie.link(:text, 'Forums Moderation').href
      assert_equal $SITE_URL + 'controlpanel/Setup.aspx', ie.link(:text, 'Administration').href
      assert_equal $SITE_URL + 'controlpanel/Reporting/default.aspx', ie.link(:text, 'Reporting').href
    end
    
    def test_08_navigateToContactSettingsPage
      ie.goto($SITE_URL + 'controlpanel/Settings/ContactInfo.aspx')
      assert(ie.contains_text("Contact"))
    end
    
    def test_09_verifyLinksExistOnContactSettingsPage
      assert(ie.link(:text, 'Help').exists?)
      assert(ie.link(:text, 'Inbox').exists?)
      assert(ie.link(:text, 'Exit Control Panel and Return to Site').exists?)
      assert(ie.link(:text, 'Dashboard').exists?)
      assert(ie.link(:text, 'My Blogs').exists?)
      assert(ie.link(:text, 'My Photos').exists?)
      assert(ie.link(:text, 'My Files').exists?)
      assert(ie.link(:text, 'Forums Moderation').exists?)
      assert(ie.link(:text, 'Administration').exists?)
      assert(ie.link(:text, 'Reporting').exists?)
      assert(ie.link(:text, 'General Site Settings').exists?)
      assert(ie.link(:text, 'Site Name & Description').exists?)
      assert(ie.link(:text, 'Applications').exists?)
      assert(ie.link(:text, 'Contact Info').exists?)
      assert(ie.link(:text, 'RSS Settings').exists?)
      assert(ie.link(:text, 'Post Settings').exists?)
      assert(ie.link(:text, 'Date / Time Settings').exists?)
      assert(ie.link(:text, 'Email Settings').exists?)
      assert(ie.link(:text, 'IP Address Tracking').exists?)
      assert(ie.link(:id, /Helpicon10$/).exists?)
      assert(ie.link(:id, /Helpicon1$/).exists?)
      assert(ie.link(:id, /Helpicon2$/).exists?)
      assert(ie.link(:id, /Helpicon3$/).exists?)
      assert(ie.link(:id, /Helpicon4$/).exists?)
      assert(ie.link(:id, /SaveButton$/).exists?)
      assert(ie.link(:text, 'Telligent').exists?)
    end
    
    def test_10_verifyFieldsExistOnContactSettingsPage
      assert(ie.text_field(:id, /TaskRegion_AdminEmailAddress$/).exists?)
      assert(ie.text_field(:id, /TaskRegion_CompanyName$/).exists?)
      assert(ie.text_field(:id, /TaskRegion_CompanyEmailAddress$/).exists?)
      assert(ie.text_field(:id, /TaskRegion_CompanyFaxNumber$/).exists?)
      assert(ie.text_field(:id, /TaskRegion_CompanyAddress$/).exists?)
    end
    
    def test_11_populateNewSettingsAndSaveSettings
      ie.text_field(:id, /TaskRegion_AdminEmailAddress$/).value = $AdminEmail
      ie.text_field(:id, /TaskRegion_CompanyName$/).value = $OrgName
      ie.text_field(:id, /TaskRegion_CompanyEmailAddress$/).value = $OrgEmail
      ie.text_field(:id, /TaskRegion_CompanyFaxNumber$/).value = $OrgFax
      ie.text_field(:id, /TaskRegion_CompanyAddress$/).value = $OrgPhone
      
      ie.link(:id, /TaskRegion_SaveButton$/).click
      assert(ie.contains_text('Settings successfully saved'))
    end
    
    def test_12_verifySettingsSavedSuccessfully
      assert_equal ie.text_field(:id, /TaskRegion_AdminEmailAddress$/).value, $AdminEmail
      assert_equal ie.text_field(:id, /TaskRegion_CompanyName$/).value, $OrgName
      assert_equal ie.text_field(:id, /TaskRegion_CompanyEmailAddress$/).value, $OrgEmail
      assert_equal ie.text_field(:id, /TaskRegion_CompanyFaxNumber$/).value, $OrgFax
      assert_equal ie.text_field(:id, /TaskRegion_CompanyAddress$/).value, $OrgPhone
    end
    
end